FROM vllm-ascend:v0.11.0rc0

# 设置环境变量，避免交互式安装
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH="/data/develop/miniconda/install/bin:${PATH}"

# 创建必要的目录
RUN mkdir -p /data/develop/miniconda && \
    mkdir -p /data/work

WORKDIR /data/develop/miniconda

# 更新并安装系统依赖
RUN apt update && \
    apt install -y \
    vim \
    wget \
    curl \
    git \
    build-essential \
    pkg-config \
    gfortran \
    libblas-dev \
    liblapack-dev \
    libatlas-base-dev \
    libsndfile1-dev \
    libsamplerate0-dev \
    ffmpeg \
    libavcodec-dev \
    libavformat-dev \
    libavutil-dev \
    libswresample-dev \
    libswscale-dev \
    libjpeg-dev \
    libpng-dev \
    libtiff-dev \
    libopenexr-dev \
    libgstreamer1.0-dev \
    libgstreamer-plugins-base1.0-dev && \
    rm -rf /var/lib/apt/lists/*

# 下载并安装 Miniconda
RUN wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_4.9.2-Linux-aarch64.sh && \
    bash Miniconda3-py39_4.9.2-Linux-aarch64.sh -b -p /data/develop/miniconda/install && \
    rm -f Miniconda3-py39_4.9.2-Linux-aarch64.sh

# 初始化 conda
RUN /data/develop/miniconda/install/bin/conda init bash

# 创建 conda 环境并安装 Python 包
RUN /data/develop/miniconda/install/bin/conda create -n hf-npu python==3.10 -y && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install soundfile==0.13.1 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install scipy==1.15.3 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install aiofiles==25.1.0 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install aiohttp==3.13.2 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install librosa==0.10.1 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install python-dotenv==1.2.1 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install fastapi && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install uvicorn[standard] && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install torch==2.4.0 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install torch-npu==2.4.0 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install torchao==0.14.1 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install torchaudio==2.4.0 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install torchvision==0.19.0 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install transformers==4.38.0 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install psutil && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install python-multipart==0.0.20 && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip uninstall numpy -y && \
    /data/develop/miniconda/install/bin/conda run -n hf-npu pip install numpy==1.26.1

# 设置工作目录
WORKDIR /data/work

# 设置默认激活 conda 环境
SHELL ["/bin/bash", "-c"]
RUN echo "conda activate hf-npu" >> ~/.bashrc

# 复制模型，已经下载好的
COPY ./app /data/work/app

COPY ./model/audeering /data/model/audeering

WORKDIR  /data/work/app

# 设置Ascend CANN库路径（如果挂载了宿主机目录，这些路径会自动生效）
# 注意：这些路径在运行时通过卷挂载从宿主机提供
# 包含所有可能的库路径，确保能找到 libascend_hal.so
ENV LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/stub:/usr/local/Ascend/add-ons:/usr/local/Ascend/driver/lib:$LD_LIBRARY_PATH
ENV ASCEND_RT_VISIBLE_DEVICES=0

# 激活 conda 环境并运行主程序
# 需要先初始化 conda，然后激活环境
CMD ["/bin/bash", "-c", "/data/develop/miniconda/install/envs/hf-npu/bin/python main.py"]